<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-03 08:58:45
 * @LastEditTime: 2019-09-01 23:54:05
 * @LastEditors: Please set LastEditors
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var str = '1,2,1,2,2';
    var reg = /2/g; //g叫做全部匹配
    // var str2 = str.replace('金哥','**');//不用正则只能匹配到第一个金哥并替换掉
    var str2 = str.replace(reg, ''); //找到全部并替换
    console.log(str2.split(','));
</script>

</html>